/**
 * 
 */
package properties;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;

/**
 * This class provides the property management for the application.
 * @author Kevin Wagner
 * @version 1.0
 */
public class DefaultProperties extends Properties {

	private static final long serialVersionUID = -5523427987955916715L;
	private final String base="properties.lang.ufr";
	private ResourceBundle bundle;

	/**
	 * Creates a new property object
	 */
	public DefaultProperties(){
		try {
			this.load(new FileReader("properties.prop"));
		} catch (Exception e) {
			loadDefaults();
			try {
				this.store(new FileWriter("properties.prop"), "Ultimate File Renamer Properties");
			} catch (IOException e1) {
			}
		}
		bundle=ResourceBundle.getBundle(base, new Locale(getProperty("lang")));
	}
	
	
	/**
	 * Load default values.
	 */
	private void loadDefaults(){
		this.setProperty("lang", "de");
	}
	
	/**
	 * 
	 * @param key the key for the text
	 * @return the String for the selected language
	 */
	public String getLocalizedText(String key){
		return bundle.getString(key);
	}
	
	/**
	 * Saves the properties to the file properties.prop.
	 */
	public void saveProperties(){
		try {
			this.store(new FileWriter("properties.prop"), "Ultimate File Renamer Properties");
		} catch (IOException e1) {
		}
	}
}
